// 这个文件用于配置路由规则
// import Home from '@/pages/Home'
// import Login from '@/pages/Login'
// import Register from '@/pages/Register'
// import Search from '@/pages/Search'
// import Test from '@/pages/Test'
// import Detail from '@/pages/Detail'
// import AddCartSuccess from '@/pages/AddCartSuccess'
// import ShopCart from '@/pages/ShopCart'
// import Trade from '@/pages/Trade'
// import Pay from '@/pages/Pay'
// import PaySuccess from '@/pages/PaySuccess'
// import Center from '@/pages/Center'
// import MyOrder from '@/pages/Center/MyOrder'
// import GroupOrder from '@/pages/Center/GroupOrder'

//路由懒加载
const Home = () => import('@/pages/Home')
const Login = () => import('@/pages/Login')
const Register = () => import('@/pages/Register')
const Search = () => import('@/pages/Search')
const Test = () => import('@/pages/Test')
const Detail = () => import('@/pages/Detail')
const AddCartSuccess = () => import('@/pages/AddCartSuccess')
const ShopCart = () => import('@/pages/ShopCart')
const Trade = () => import('@/pages/Trade')
const Pay = () => import('@/pages/Pay')
const PaySuccess = () => import('@/pages/PaySuccess')
const Center = () => import('@/pages/Center')
const MyOrder = () => import('@/pages/Center/MyOrder')
const GroupOrder = () => import('@/pages/Center/GroupOrder')

export default [//一级路由
    {
        path: '/home',
        component: Home
    },
    {
        path: '/login',
        component: Login,
        //登录和注册组件展示的时候Footer组件是不展示的，可以使用路由里面mate配置项进行配置使用控制Footer显示与否,在组件中通过this.$route可以访问到当前组件，里面有meta属性
        meta: {
            isHidden: true
        }
    },
    {
        path: '/register',
        component: Register,
        // 和登录组件一样，登录和注册组件展示的时候Footer组件是不展示的
        meta: {
            isHidden: true
        }
    },
    {
        path: '/search/:keyword?',//传参占位符
        component: Search,
        name: 'search',
        props: (route) => ({ ...route.params })//简化组件模板使用数据
    },
    {//进入页面默认展示home组件
        path: '/',
        redirect: '/home'
    },
    {
        path: '/test',
        component: Test
    },
    {
        path: '/detail/:skuId',
        component: Detail
    },
    {
        path: '/addcart',
        component: AddCartSuccess
    },
    {
        path: '/shopcart',
        component:ShopCart
    },
    {
        path: '/trade',
        component: Trade,
        beforeEnter: (to,from,next) => {//路由独享守卫
            if (from.path.indexOf('/shopcart') !== -1 || from.path.indexOf('/login')!==-1 || from.path==='/') {//从shopcart跳转过来
                next() 
            } else {
                next(false)
            }
        }
    },
    {
        path: '/pay/:orderId',//传递订单号
        component: Pay,
        beforeEnter: (to, from, next) => {//路由独享守卫
            if (from.path.indexOf('/trade') !== -1) {//从shopcart跳转过来
                next()
            } else {
                next(false)
            }
        }
    },
    {
        path: '/paysuccess',
        component: PaySuccess,
        beforeEnter: (to, from, next) => {//路由独享守卫
            if (from.path.indexOf('/trade') !== -1) {//从shopcart跳转过来
                next()
            } else {
                next(false)
            }
        }
    },
    {
        path: '/center',
        component: Center,
        children: [
            {
                path: 'myorder',
                component: MyOrder
            },
            {
                path: 'grouporder',
                component:GroupOrder
            },
            {
                path: '',
                redirect:'myorder'
            }
        ]
    }
]